package com.cheems.controller;

import com.cheems.entity.DTO.picDTO;
import com.cheems.entity.DTO.picUpdateDTO;
import com.cheems.entity.DTO.wallListDTO;
import com.cheems.entity.Pojo.pic;
import com.cheems.entity.Result.PageResult;
import com.cheems.entity.Result.Result;
import com.cheems.service.PicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "图片相关接口")
public class PicController {

    @Autowired
    private PicService picService;
    /**
     * 获取分类中壁纸列表
     * @return
     */
    @PostMapping ("/wallList")
    @ApiOperation("获取分类中壁纸列表")
    public Result<PageResult> wallList(@RequestBody wallListDTO wallListDTO){
        log.info("图片列表前端传递参数为,{}",wallListDTO);
        PageResult pageResult = picService.wallList(wallListDTO);
        return Result.success(pageResult);
    }

    /**
     * 随机获取图片
     * @return
     */
    @GetMapping("/randomWall")
    @ApiOperation("随机获取图片")
    public Result<List<pic>> randomWall(){
        log.info("获取随机图片");
        List<pic> picList = picService.randomWall();
        return Result.success(picList);
    }

    /**
     * 获取单个壁纸详情
     */
    @GetMapping("/detailWall/{id}")
    @ApiOperation("获取单个壁纸详情")
    public Result<pic> detailWall(@PathVariable Integer id){
        log.info("获取单个壁纸详情参数为,{}",id);
        pic pic = picService.detailWall(id);
        return Result.success(pic);
    }

    /**
     * 新增壁纸
     * @return
     */
    @PostMapping("/addPic")
    @ApiOperation("新增壁纸")
    public Result addPic(@RequestBody picDTO picDTO){
        log.info("新增壁纸参数为,{}",picDTO);
        picService.addPic(picDTO);
        return Result.success();
    }

    /**
     * 修改壁纸
     * @return
     */
    @PostMapping("updatePic")
    @ApiOperation("修改壁纸信息")
    public Result updatePic(@RequestBody picUpdateDTO picUpdateDTO){
        log.info("修改壁纸信息为,{}",picUpdateDTO);
        picService.updatePic(picUpdateDTO);
        return Result.success();
    }

    @GetMapping("/delPic/{id}")
    @ApiOperation("删除壁纸")
    public Result delPic(@PathVariable Integer id){
        log.info("删除图片,{}",id);
        picService.delPic(id);
        return Result.success(id);
    }
}
